﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace Himp.Platform
{
    public class DeptTreeService : PlatformAppService
    {
        private IRepository<Dept, Guid> _deptRepository;

        public DeptTreeService(IRepository<Dept, Guid> DeptRepository)
        {
            _deptRepository = DeptRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<List<DeptDto>> GetListAsync()
        {
            var iQuery = await _deptRepository.WithDetailsAsync();
            var depts = iQuery.ToList();
            depts = depts.Where(i => i.ParentId == null).ToList();
            var itemsDto = ObjectMapper.Map<List<Dept>, List<DeptDto>>(depts);

            return itemsDto;
        }
    }
}
